//
//  loginViewController.m
//  MaxMovie
//
//  Created by Maxdong on 14-12-30.
//  Copyright (c) 2014年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "loginViewController.h"
#import "ShowViewController.h"
#import "Singleton.h"
#import "RegistViewController.h"
@interface loginViewController ()

@end

@implementation loginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"our.png"]];
    [self create];
    [self createLeft];
}


- (void)create
{
    //右button
    UIButton * rightb =[UIButton buttonWithType:UIButtonTypeSystem];
    rightb.frame =CGRectMake(280, 50, 20, 20);
    UIImage * img =[UIImage imageNamed:@"guanbi.png"];
    [rightb setBackgroundImage:img forState:UIControlStateNormal];
    [rightb addTarget:self action:@selector(rightbAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightb];

    
    
    UILabel *label1 =[[UILabel alloc] initWithFrame:CGRectMake(40, 190, 80, 40)];
    //label1.backgroundColor =[UIColor ]
    [label1 setText:@"用户名:"];
    [label1 setTextColor:[UIColor whiteColor]];
    [self.view addSubview:label1];
    
    
    [label1 release];
    
    UILabel *label2 =[[UILabel alloc] initWithFrame:CGRectMake(40, 260, 80, 40)];
    [label2 setText:@"密 码:"];
    [label2 setTextColor:[UIColor whiteColor]];
    [self.view addSubview:label2];
    [label2 release];
    
    
    UITextField * utf =[[UITextField alloc] initWithFrame:CGRectMake(140, 190, 160, 40)];
    utf.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:utf];
    utf.placeholder =@"请输入用户名";
    utf.tag=10;
    [utf release];
    
    
    
    UITextField * utf1 =[[UITextField alloc] initWithFrame:CGRectMake(140, 260, 160, 40)];
    [self.view addSubview:utf1];
    utf1.borderStyle = UITextBorderStyleRoundedRect;
    utf1.placeholder =@"请输入密码";
    [utf1 setSecureTextEntry:YES];
    utf1.tag=20;
    [utf1 release];
    
    UIButton * button1 =[[UIButton alloc] initWithFrame:CGRectMake(30, 350, 100, 30)];
    [button1 setTitle:@"登陆" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button1.backgroundColor =[UIColor whiteColor];
    [button1 addTarget:self action:@selector(buttonAction3:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button1];
    
    UIButton * button2 =[[UIButton alloc] initWithFrame:CGRectMake(190, 350, 100, 30)];
    [button2 setTitle:@"注册" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button2.backgroundColor =[UIColor whiteColor];
    [button2 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:button2];
}


- (void)createLeft
{
    UIButton * button =[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame =CGRectMake(20, 20, 60, 40);
    [button setTitle:@"登陆" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.LeftBarButtonItem =[[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
    
}

- (void)buttonAction3:(id)sender
{
    UITextField * text1 =(UITextField *)[self.view viewWithTag:10];
    UITextField * text2 =(UITextField *)[self.view viewWithTag:20];
    if ([text1.text isEqualToString:@"zhangsan"] && [text2.text isEqualToString:@"123"]) {
        UIAlertView * view =[[UIAlertView alloc] initWithTitle:@"登陆成功" message:@"欢迎回来.." delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
        [view show];
        
        ShowViewController * four =[[ShowViewController alloc] init];
        Singleton *sing = [Singleton shareInstance];
        sing.logined = YES;
        
        //        UINavigationController * na =[[UINavigationController alloc] initWithRootViewController:four];
        //        [na.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_nav.png"] forBarMetrics:UIBarMetricsDefault];
        
        [self.navigationController pushViewController:four animated:YES];
    }else if ([text1.text isEqualToString:@""] || [text2.text isEqualToString:@""] || [text1.text isEqualToString:nil] || [text2.text isEqualToString:nil]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录失败" message:@"请重新输入或注册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        [alert show];
    }
}
- (void)buttonAction2:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)buttonAction1:(id)sender
{
    RegistViewController *regist =[[RegistViewController alloc] init];
    [self presentViewController:regist animated:YES completion:^{
        
    }];
    

    
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITextField * text1 =(UITextField *)[self.view viewWithTag:10];
    UITextField * text2 =(UITextField *)[self.view viewWithTag:20];
    [text1 resignFirstResponder];
    [text2 resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //取消第一响应者  让键盘消失
    [textField resignFirstResponder];
    return YES;
}


//右button
- (void)rightbAction:(id)sender
{
    //    WillNRViewController * willnr=[[WillNRViewController alloc] init];
    //ShowViewController * will =[[ShowViewController alloc] init];
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
